<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::Timestamp::Factory - openssl: Ruby Standard Library Documentation</title>


<script src="../../js/navigation.js" defer></script>
<script src="../../js/search.js" defer></script>
<script src="../../js/search_index.js" defer></script>
<script src="../../js/searcher.js" defer></script>
<script src="../../js/darkfish.js" defer></script>

<script src="../../js/jquery-3.2.0.min.js"></script>

<script src="../../js/vue.min.js"></script>
<script src="../../js/js.cookie.min.js"></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../../css/rdoc.css" rel="stylesheet">
<link href="../../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
  var darkModeCsseHref = "../../css/rdoc-dm.css"
  var defaultModeCssHref = "../../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-Example-3A+Inclusion+of+-28untrusted-29+intermediate+certificates">Example: Inclusion of (untrusted) intermediate certificates</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-Attributes">Attributes</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-default_policy_id">default_policy_id</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-serial_number">serial_number</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-gen_time">gen_time</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-additional_certs">additional_certs</a>
    <li><a href="#class-OpenSSL::Timestamp::Factory-label-allowed_digests">allowed_digests</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-create_timestamp">#create_timestamp</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::Timestamp::Factory">
    <h1 id="class-OpenSSL::Timestamp::Factory" class="class">
      class OpenSSL::Timestamp::Factory
    </h1>

    <section class="description">
    
<p>Used to generate a <a href="Response.html"><code>Response</code></a> from scratch.</p>

<p>Please bear in mind that the implementation will always apply and prefer the policy object identifier given in the request over the default policy id specified in the <a href="Factory.html"><code>Factory</code></a>. As a consequence, <code>default_policy_id</code> will only be applied if no <a href="Request.html#method-i-policy_id"><code>Request#policy_id</code></a> was given. But this also means that one needs to check the policy identifier in the request manually before creating the <a href="Response.html"><code>Response</code></a>, e.g. to check whether it complies to a specific set of acceptable policies.</p>

<p>There exists also the possibility to add certificates (instances of <a href="../X509/Certificate.html"><code>OpenSSL::X509::Certificate</code></a>) besides the timestamping certificate that will be included in the resulting timestamp token if <a href="Request.html#method-i-cert_requested-3F"><code>Request#cert_requested?</code></a> is <code>true</code>. Ideally, one would also include any intermediate certificates (the root certificate can be left out - in order to trust it any verifying party will have to be in its possession anyway). This simplifies validation of the timestamp since these intermediate certificates are “already there” and need not be passed as external parameters to <a href="Response.html#method-i-verify"><code>Response#verify</code></a> anymore, thus minimizing external resources needed for verification.</p>

<h3 id="class-OpenSSL::Timestamp::Factory-label-Example-3A+Inclusion+of+-28untrusted-29+intermediate+certificates">Example: Inclusion of (untrusted) intermediate certificates<span><a href="#class-OpenSSL::Timestamp::Factory-label-Example-3A+Inclusion+of+-28untrusted-29+intermediate+certificates">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Assume we received a timestamp request that has set <a href="Request.html#method-i-policy_id"><code>Request#policy_id</code></a> to <code>nil</code> and <a href="Request.html#method-i-cert_requested-3F"><code>Request#cert_requested?</code></a> to true. The raw request bytes are stored in a variable called <code>req_raw</code>. We’d still like to integrate the necessary intermediate certificates (in <code>inter1.cer</code> and <code>inter2.cer</code>) to simplify validation of the resulting <a href="Response.html"><code>Response</code></a>. <code>ts.p12</code> is a PKCS#12-compatible file including the private key and the timestamping certificate.</p>

<pre class="ruby"><span class="ruby-identifier">req</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Timestamp</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">raw_bytes</span>)
<span class="ruby-identifier">p12</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS12</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">binread</span>(<span class="ruby-string">&#39;ts.p12&#39;</span>), <span class="ruby-string">&#39;pwd&#39;</span>)
<span class="ruby-identifier">inter1</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Certificate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">binread</span>(<span class="ruby-string">&#39;inter1.cer&#39;</span>))
<span class="ruby-identifier">inter2</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Certificate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">binread</span>(<span class="ruby-string">&#39;inter2.cer&#39;</span>))
<span class="ruby-identifier">fac</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Timestamp</span><span class="ruby-operator">::</span><span class="ruby-constant">Factory</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">fac</span>.<span class="ruby-identifier">gen_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
<span class="ruby-identifier">fac</span>.<span class="ruby-identifier">serial_number</span> = <span class="ruby-value">1</span>
<span class="ruby-identifier">fac</span>.<span class="ruby-identifier">allowed_digests</span> = [<span class="ruby-string">&quot;sha256&quot;</span>, <span class="ruby-string">&quot;sha384&quot;</span>, <span class="ruby-string">&quot;sha512&quot;</span>]
<span class="ruby-comment">#needed because the Request contained no policy identifier</span>
<span class="ruby-identifier">fac</span>.<span class="ruby-identifier">default_policy_id</span> = <span class="ruby-string">&#39;1.2.3.4.5&#39;</span>
<span class="ruby-identifier">fac</span>.<span class="ruby-identifier">additional_certificates</span> = [ <span class="ruby-identifier">inter1</span>, <span class="ruby-identifier">inter2</span> ]
<span class="ruby-identifier">timestamp</span> = <span class="ruby-identifier">fac</span>.<span class="ruby-identifier">create_timestamp</span>(<span class="ruby-identifier">p12</span>.<span class="ruby-identifier">key</span>, <span class="ruby-identifier">p12</span>.<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">req</span>)
</pre>

<h2 id="class-OpenSSL::Timestamp::Factory-label-Attributes">Attributes<span><a href="#class-OpenSSL::Timestamp::Factory-label-Attributes">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="class-OpenSSL::Timestamp::Factory-label-default_policy_id"><a href="Factory.html#attribute-i-default_policy_id"><code>default_policy_id</code></a><span><a href="#class-OpenSSL::Timestamp::Factory-label-default_policy_id">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p><a href="Request.html#method-i-policy_id"><code>Request#policy_id</code></a> will always be preferred over this if present in the <a href="Request.html"><code>Request</code></a>, only if <a href="Request.html#method-i-policy_id"><code>Request#policy_id</code></a> is nil default_policy will be used. If none of both is present, a <a href="TimestampError.html"><code>TimestampError</code></a> will be raised when trying to create a <a href="Response.html"><code>Response</code></a>.</p>

<p>call-seq:</p>

<pre>factory.default_policy_id = &quot;string&quot; -&gt; string
factory.default_policy_id            -&gt; string or nil</pre>

<h3 id="class-OpenSSL::Timestamp::Factory-label-serial_number"><a href="Factory.html#attribute-i-serial_number"><code>serial_number</code></a><span><a href="#class-OpenSSL::Timestamp::Factory-label-serial_number">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Sets or retrieves the serial number to be used for timestamp creation. Must be present for timestamp creation.</p>

<p>call-seq:</p>

<pre>factory.serial_number = number -&gt; number
factory.serial_number          -&gt; number or nil</pre>

<h3 id="class-OpenSSL::Timestamp::Factory-label-gen_time"><a href="Factory.html#attribute-i-gen_time"><code>gen_time</code></a><span><a href="#class-OpenSSL::Timestamp::Factory-label-gen_time">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Sets or retrieves the Time value to be used in the <a href="Response.html"><code>Response</code></a>. Must be present for timestamp creation.</p>

<p>call-seq:</p>

<pre>factory.gen_time = Time -&gt; Time
factory.gen_time        -&gt; Time or nil</pre>

<h3 id="class-OpenSSL::Timestamp::Factory-label-additional_certs"><a href="Factory.html#attribute-i-additional_certs"><code>additional_certs</code></a><span><a href="#class-OpenSSL::Timestamp::Factory-label-additional_certs">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Sets or retrieves additional certificates apart from the timestamp certificate (e.g. intermediate certificates) to be added to the <a href="Response.html"><code>Response</code></a>. Must be an Array of <a href="../X509/Certificate.html"><code>OpenSSL::X509::Certificate</code></a>.</p>

<p>call-seq:</p>

<pre>factory.additional_certs = [cert1, cert2] -&gt; [ cert1, cert2 ]
factory.additional_certs                  -&gt; array or nil</pre>

<h3 id="class-OpenSSL::Timestamp::Factory-label-allowed_digests"><a href="Factory.html#attribute-i-allowed_digests"><code>allowed_digests</code></a><span><a href="#class-OpenSSL::Timestamp::Factory-label-allowed_digests">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Sets or retrieves the digest algorithms that the factory is allowed create timestamps for. Known vulnerable or weak algorithms should not be allowed where possible. Must be an Array of String or <a href="../Digest.html"><code>OpenSSL::Digest</code></a> subclass instances.</p>

<p>call-seq:</p>

<pre>factory.allowed_digests = [&quot;sha1&quot;, OpenSSL::Digest.new(&#39;SHA256&#39;).new] -&gt; [ &quot;sha1&quot;, OpenSSL::Digest) ]
factory.allowed_digests                                               -&gt; array or nil</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">



        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-additional_certs" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">additional_certs</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-allowed_digests" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">allowed_digests</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-default_policy_id" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">default_policy_id</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-gen_time" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">gen_time</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-serial_number" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">serial_number</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
            </section>


                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-create_timestamp" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          create_timestamp(key, certificate, request) &rarr; Response
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a <a href="Response.html"><code>Response</code></a> with the help of an <a href="../PKey.html"><code>OpenSSL::PKey</code></a>, an <a href="../X509/Certificate.html"><code>OpenSSL::X509::Certificate</code></a> and a <a href="Request.html"><code>Request</code></a>.</p>

<p>Mandatory parameters for timestamp creation that need to be set in the Request:</p>
<ul><li>
<p><a href="Request.html#method-i-algorithm"><code>Request#algorithm</code></a></p>
</li><li>
<p><a href="Request.html#method-i-message_imprint"><code>Request#message_imprint</code></a></p>
</li></ul>

<p>Mandatory parameters that need to be set in the Factory:</p>
<ul><li>
<p><a href="Factory.html#attribute-i-serial_number"><code>Factory#serial_number</code></a></p>
</li><li>
<p><a href="Factory.html#attribute-i-gen_time"><code>Factory#gen_time</code></a></p>
</li><li>
<p><a href="Factory.html#attribute-i-allowed_digests"><code>Factory#allowed_digests</code></a></p>
</li></ul>

<p>In addition one of either <a href="Request.html#method-i-policy_id"><code>Request#policy_id</code></a> or <a href="Factory.html#attribute-i-default_policy_id"><code>Factory#default_policy_id</code></a> must be set.</p>

<p>Raises a <a href="TimestampError.html"><code>TimestampError</code></a> if creation fails, though successfully created error responses may be returned.</p>

                              <div class="method-source-code" id="create_timestamp-source">
            <pre>static VALUE
ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
{
    VALUE serial_number, def_policy_id, gen_time, additional_certs, allowed_digests;
    VALUE str;
    STACK_OF(X509) *inter_certs;
    VALUE tsresp, ret = Qnil;
    EVP_PKEY *sign_key;
    X509 *tsa_cert;
    TS_REQ *req;
    TS_RESP *response = NULL;
    TS_RESP_CTX *ctx = NULL;
    BIO *req_bio;
    ASN1_INTEGER *asn1_serial = NULL;
    ASN1_OBJECT *def_policy_id_obj = NULL;
    long lgen_time;
    const char * err_msg = NULL;
    int status = 0;

    tsresp = NewTSResponse(cTimestampResponse);
    tsa_cert = GetX509CertPtr(certificate);
    sign_key = GetPrivPKeyPtr(key);
    GetTSRequest(request, req);

    gen_time = ossl_tsfac_get_gen_time(self);
    if (!rb_obj_is_instance_of(gen_time, rb_cTime)) {
        err_msg = &quot;@gen_time must be a Time.&quot;;
        goto end;
    }
    lgen_time = NUM2LONG(rb_funcall(gen_time, rb_intern(&quot;to_i&quot;), 0));

    serial_number = ossl_tsfac_get_serial_number(self);
    if (NIL_P(serial_number)) {
        err_msg = &quot;@serial_number must be set.&quot;;
        goto end;
    }
    asn1_serial = num_to_asn1integer(serial_number, NULL);

    def_policy_id = ossl_tsfac_get_default_policy_id(self);
    if (NIL_P(def_policy_id) &amp;&amp; !TS_REQ_get_policy_id(req)) {
        err_msg = &quot;No policy id in the request and no default policy set&quot;;
        goto end;
    }
    if (!NIL_P(def_policy_id) &amp;&amp; !TS_REQ_get_policy_id(req)) {
        def_policy_id_obj = (ASN1_OBJECT*)rb_protect(obj_to_asn1obj_i, (VALUE)def_policy_id, &amp;status);
        if (status)
            goto end;
    }

    if (!(ctx = TS_RESP_CTX_new())) {
        err_msg = &quot;Memory allocation failed.&quot;;
        goto end;
    }

    TS_RESP_CTX_set_serial_cb(ctx, ossl_tsfac_serial_cb, &amp;asn1_serial);
    if (!TS_RESP_CTX_set_signer_cert(ctx, tsa_cert)) {
        err_msg = &quot;Certificate does not contain the timestamping extension&quot;;
        goto end;
    }

    additional_certs = ossl_tsfac_get_additional_certs(self);
    if (rb_obj_is_kind_of(additional_certs, rb_cArray)) {
        inter_certs = ossl_protect_x509_ary2sk(additional_certs, &amp;status);
        if (status)
                goto end;

        /* this dups the sk_X509 and ups each cert&#39;s ref count */
        TS_RESP_CTX_set_certs(ctx, inter_certs);
        sk_X509_pop_free(inter_certs, X509_free);
    }

    TS_RESP_CTX_set_signer_key(ctx, sign_key);
    if (!NIL_P(def_policy_id) &amp;&amp; !TS_REQ_get_policy_id(req))
        TS_RESP_CTX_set_def_policy(ctx, def_policy_id_obj);
    if (TS_REQ_get_policy_id(req))
        TS_RESP_CTX_set_def_policy(ctx, TS_REQ_get_policy_id(req));
    TS_RESP_CTX_set_time_cb(ctx, ossl_tsfac_time_cb, &amp;lgen_time);

    allowed_digests = ossl_tsfac_get_allowed_digests(self);
    if (rb_obj_is_kind_of(allowed_digests, rb_cArray)) {
        int i;
        VALUE rbmd;
        const EVP_MD *md;

        for (i = 0; i &lt; RARRAY_LEN(allowed_digests); i++) {
            rbmd = rb_ary_entry(allowed_digests, i);
            md = (const EVP_MD *)rb_protect(ossl_evp_get_digestbyname_i, rbmd, &amp;status);
            if (status)
                goto end;
            TS_RESP_CTX_add_md(ctx, md);
        }
    }

    str = rb_protect(ossl_to_der, request, &amp;status);
    if (status)
        goto end;

    req_bio = (BIO*)rb_protect(ossl_obj2bio_i, (VALUE)&amp;str, &amp;status);
    if (status)
        goto end;

    response = TS_RESP_create_response(ctx, req_bio);
    BIO_free(req_bio);

    if (!response) {
        err_msg = &quot;Error during response generation&quot;;
        goto end;
    }

    /* bad responses aren&#39;t exceptional, but openssl still sets error
     * information. */
    ossl_clear_error();

    SetTSResponse(tsresp, response);
    ret = tsresp;

end:
    ASN1_INTEGER_free(asn1_serial);
    ASN1_OBJECT_free(def_policy_id_obj);
    TS_RESP_CTX_free(ctx);
    if (err_msg)
        rb_exc_raise(ossl_make_error(eTimestampError, rb_str_new_cstr(err_msg)));
    if (status)
        rb_jump_tag(status);
    return ret;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

